package us.icitap.cm.business.entities;


import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

import org.eclipse.persistence.annotations.Customizer;

import us.icitap.cm.utils.MyCustomizer;

@Entity
@Customizer(MyCustomizer.class)
@Table(name="EVENT_REPORT", schema="MPC")
public class EventReport implements Serializable {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 8752060138043259802L;

	@Id
	@Column(insertable=false, updatable = false,nullable=false)
	private Integer id;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="EVENT_TIME_FROM")
	private Date eventTimeFrom;
	

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="EVENT_TIME_TO")
	private Date eventTimeTo;
	
	@ManyToOne
	@JoinColumn(name="ORG_STRUCTURE_ID")
	private OrgStructure orgStructure;
	
	@ManyToOne
	@JoinColumn(name="ER_OFFICER_ID")
	private Officer erOfficer; 
	
	@Column(name="DIRECT_STRUCTURE_ID")
	private Integer directStructureId;
	
	@ManyToOne
	@JoinColumn(name="REPORT_METHOD_ID")
	private AppList reportingMethod;
	

	
	
	@Column(name="DOMESTIC_VIOLENCE")
	private boolean domesticViolence;
	
	@Column(name="REMAINED_ATTEMPT")
	private boolean remainedAttempt;
	
	@ManyToOne
	@JoinColumn(name="MODUS_OPERANDUS_ID")
	private AppList modusOperandus;
	
	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(name="MPC.ER_TOOL_USED", joinColumns=@JoinColumn(name="ER_ID"), inverseJoinColumns=@JoinColumn(name="UT_ID"))
	private List<AppList> toolUsedList;
	
	@ManyToOne
	@JoinColumn(name="MOTIVATION_ID")
	private AppList motivation;
	
	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(name="MPC.ER_CONSEQUENCE", joinColumns=@JoinColumn(name="ER_ID"), inverseJoinColumns=@JoinColumn(name="CONSEQUENCE_ID"))
	private List<AppList> consequenceList;
	

	@OneToOne
	@JoinColumn(name="ID",nullable=false)
	private Report report;
	
	@OneToOne(cascade=CascadeType.REFRESH)
	@JoinColumn(name="UNIQUE_NUMBER")
	@NotNull(message="Numri unik nuk mund te jete bosh")
	private UniqueNumber uniqueNumber;

	
	@ManyToOne(cascade=CascadeType.ALL)
	@JoinColumn(name="PLACE_ID")
	private Place place;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}



	public UniqueNumber getUniqueNumber() {
		return uniqueNumber;
	}

	public void setUniqueNumber(UniqueNumber uniqueNumber) {
		this.uniqueNumber = uniqueNumber;
	}

	public Date getEventTimeFrom() {
		return eventTimeFrom;
	}

	public void setEventTimeFrom(Date eventTimeFrom) {
		this.eventTimeFrom = eventTimeFrom;
	}

	public Date getEventTimeTo() {
		return eventTimeTo;
	}

	public void setEventTimeTo(Date eventTimeTo) {
		this.eventTimeTo = eventTimeTo;
	}

	public OrgStructure getOrgStructure() {
		return orgStructure;
	}

	public void setOrgStructure(OrgStructure orgStructure) {
		this.orgStructure = orgStructure;
	}

	public Officer getErOfficer() {
		return erOfficer;
	}

	public void setErOfficer(Officer erOfficer) {
		this.erOfficer = erOfficer;
	}

	public Integer getDirectStructureId() {
		return directStructureId;
	}

	public void setDirectStructureId(Integer directStructureId) {
		this.directStructureId = directStructureId;
	}

	public AppList getReportingMethod() {
		return reportingMethod;
	}

	public void setReportingMethod(AppList reportingMethod) {
		this.reportingMethod = reportingMethod;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		EventReport other = (EventReport) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}



	public boolean isDomesticViolence() {
		return domesticViolence;
	}

	public void setDomesticViolence(boolean domesticViolence) {
		this.domesticViolence = domesticViolence;
	}

	public boolean isRemainedAttempt() {
		return remainedAttempt;
	}

	public void setRemainedAttempt(boolean remainedAttempt) {
		this.remainedAttempt = remainedAttempt;
	}

	public AppList getModusOperandus() {
		return modusOperandus;
	}

	public void setModusOperandus(AppList modusOperandus) {
		this.modusOperandus = modusOperandus;
	}

	public List<AppList> getToolUsedList() {
		return toolUsedList;
	}

	public void setToolUsedList(List<AppList> toolUsedList) {
		this.toolUsedList = toolUsedList;
	}

	public AppList getMotivation() {
		return motivation;
	}

	public void setMotivation(AppList motivation) {
		this.motivation = motivation;
	}

	public List<AppList> getConsequenceList() {
		return consequenceList;
	}

	public void setConsequenceList(List<AppList> consequenceList) {
		this.consequenceList = consequenceList;
	}

	@Override
	public String toString() {
		if(this.getUniqueNumber().isUnGenerated())
			return this.getUniqueNumber().getUniqueNumber() + ", " + this.getReport().getPrimaryPoliceCode().getTag();
		else
			return  this.getReport().getPrimaryPoliceCode().getTag();
	}

	public Report getReport() {
		return report;
	}

	public void setReport(Report report) {
		this.report = report;
	}

	public Place getPlace() {
		return place;
	}

	public void setPlace(Place place) {
		this.place = place;
	}


	
}
